import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
//解决router版本过高 重复点击路由控制台报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function(location) {
    return originalPush.call(this, location).catch(err => err);
};

const Login = () => import('../views/login/index.vue');// 登录
const Layout = () => import('../views/layout/layout.vue');// 布局组件
const Error = () => import('../views/page/404.vue');//404
const Manager = () => import('../views/system/manager.vue');//管理人员
const Article = () => import('../views/article/index.vue');//文章管理
const ArticleInfo = () => import('../views/article/info.vue');//文章详情
const User = () => import('../views/system/user.vue');//录入人员
const Chart = () => import('../views/article/chart.vue');//数据统计
export const constantRouterMap = [
    {path: '/', name: 'login', component: Login, meta: {title: '登录', login: true}},
    {
        path: '/main', component: Layout,
        children: [
            {path: '/main', name: 'main', component: Article, meta: {title: '采集信息', show: true, 'icon': 'fa fa-home'}},
            {path: '/error', name: 'error', component: Error, meta: {title: '404', show: false}},
        ],
    },
];

export const asyncRouterMap = [
    {
        path: '/main',
        component: Layout,
        title: '系统管理',
        icon: 'fa fa-cog',
        children: [
            {path: '/manager', name: 'manager', component: Manager, meta: {title: '管理人员', show: true, auth: '1300'}},
            {path: '/info', name: 'info', component: ArticleInfo, meta: {title: '信息详情', show: false, auth: '1400'}},
            {path: '/user', name: 'user', component: User, meta: {title: '录入人员', show: true, auth: '1500'}},
            {path: '/chart', name: 'chart', component: Chart, meta: {title: '数据统计', show: true, auth: '1200'}},
        ],
    },
    {path: '*', redirect: '/error'}
];

const router = new VueRouter({
    mode: 'history',
    base: '/manage',
    routes: constantRouterMap
});

export default router;
